package com.coincalf.wallet.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.coincalf.wallet.dto.CoinConfigDto;
import com.coincalf.wallet.entity.CoinConfig;
import com.coincalf.wallet.mapper.CoinConfigMapper;
import com.coincalf.wallet.service.CoinConfigService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 币种配置信息 服务实现类
 * </p>
 *
 * @author crow
 * @since 2018-05-16
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CoinConfigServiceImpl extends ServiceImpl<CoinConfigMapper, CoinConfig> implements CoinConfigService {

    @Autowired
    private CoinConfigMapper coinConfigMapper;

    @Override
    public CoinConfig selectOneByCoinId(long coinId) {
        EntityWrapper<CoinConfig> wrap = new EntityWrapper<>();
        wrap.eq("id", coinId);
        return super.selectById(wrap);
    }

    @Override
    public CoinConfig selectOneByCoinName(String coinName) {
        EntityWrapper<CoinConfig> wrap = new EntityWrapper<>();
        wrap.eq("name", coinName);
        return super.selectOne(wrap);
    }

    @Override
    public List<CoinConfig> selectListByMainCoinId(long mainCoinId) {
        EntityWrapper<CoinConfig> wrap = new EntityWrapper<>();
        wrap.eq("main_coin_id", mainCoinId);
        return super.selectList(wrap);
    }

    @Override
    public List<CoinConfigDto> selectContractAddressesByMainCoinId(long mainCoinId) {
        return coinConfigMapper.selectContractAddressByMainCoinId(mainCoinId);
    }

}
